﻿using System;
using AutoMapper;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MsForgeReboot.Framework.Entities;
using MsForgeReboot.Framework.ViewModels;
using MsForgeReboot.Web;

namespace MsForgeReboot.Tests.Config {
    [TestClass]
    public class AutomapperConfigTest {

        [TestInitialize]
        public void TestInitialize()
        {
            AutomapperConfig.Configure();
        }

        [TestCleanup]
        public void TestCleanUp()
        {
            Mapper.Reset();
        }

        [TestMethod]
        public void EventMapsToEventEditModel() {
            var result = Mapper.Map<EventEditModel>(new Event());
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(EventEditModel));
        }

        [TestMethod]
        public void EventAuthorIdMapsToEventEditModelAuthorId() {
            var result = Mapper.Map<EventEditModel>(new Event() { Author = new User { Id = 123 } });
            Assert.AreEqual(123, result.Author.Id);
        }

        [TestMethod]
        public void EventEditModelMapsToEvent() {
            var result = Mapper.Map<Event>(new EventEditModel());
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(Event));
        }

        [TestMethod]
        public void EventEditModelAuthorIdMapsToEventAuthorId() {
            var result = Mapper.Map<Event>(new EventEditModel() { Author = new UserViewModel { Id = 123 }, Topic = "Test 123" });
            Assert.AreEqual(123, result.Author.Id);
            Assert.AreEqual("Test 123", result.Topic);
        }

        [TestMethod]
        public void UserMapsToUserViewModel() {
            var result = Mapper.Map<UserViewModel>(new User());
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(UserViewModel));
        }

        [TestMethod]
        public void UserViewModelMapsToUser() {
            var result = Mapper.Map<User>(new UserViewModel());
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(User));
        }
        
        [TestMethod]
        public void EventAuthorMapsToUserViewModel() {
            var result = Mapper.Map<EventEditModel>(new Event() { Author = new User { Id = 123, PublicName = "Test Name" } });
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result.Author, typeof(UserViewModel));
            Assert.AreEqual(result.Author.PublicName, "Test Name");
            Assert.AreEqual(result.Author.Id, 123);
        }

        [TestMethod]
        public void UserGroupMapsToUserGroupEditModel() {
            var result = Mapper.Map<UserGroupEditModel>(new UserGroup());
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(UserGroupEditModel));
        }

        [TestMethod]
        public void UserGroupEditModelMapsToUserGroup() {
            var result = Mapper.Map<UserGroup>(new UserGroupEditModel());
            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(UserGroup));
        }


    }
}
